from git import Repo

def is_update_needed(repo_path):

    repo = Repo(repo_path)
    origin = repo.remotes.origin

    # 抓取远程分支信息
    origin.fetch()

    # 获取当前本地分支和远程分支的最新 commit hash
    local_commit = repo.head.commit
    remote_commit = origin.refs[repo.active_branch.name].commit

    # 如果远程 commit 不同于本地 commit，则需要更新
    if local_commit != remote_commit:
        return True
    else:
        # print("已处于最新的更新分支，无需更新。")
        return False


def update_repository(repo_path):

    repo = Repo(repo_path)
    origin = repo.remotes.origin

    origin.pull()